package cn.yzgy.yzgyoa.ucenter.mapper;

import cn.yzgy.yzgyoa.ucenter.entity.SysOrganization;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 组织机构表
支持公司多级结构 Mapper 接口
 * </p>
 *
 * @author Yqsen
 * @since 2019-08-27
 */
public interface SysOrganizationMapper extends BaseMapper<SysOrganization> {
    /**
     * 机构集合
     * @return 机构列表
     */
    @Select(" select oid as id,parent_oid as parentId,en_abbr as enAbbr,data_perm as dataPerm,name from sys_organization where en_abbr like concat(#{enAbbr},'%')")
    List<SysOrganization> sysOrganizationList(String enAbbr);

    /**
     * 根据主键修改主键
     * @param newId 修改后主键值
     * @param oid 现主键值
     * @return 根据主键修改主键
     */
    @Update("update sys_organization set oid='${newId}' where oid = '${oid}'")
    int updatePrimaryKey(@Param("newId") Long newId,@Param("oid") Long oid);

    /**
     * 获取EnAbbr数据
     * @param wrapper 条件集
     * @return 获取EnAbbr数据
     */
    @Select("select en_abbr as enAbbr  from sys_organization  ${ew.customSqlSegment} ")
    String getEnAbbr(@Param(Constants.WRAPPER) Wrapper wrapper);

    /**
     * 新增数据主键
     * @param wrapper 条件集
     * @return 新增数据主键
     */
    @Select("select max(oid)+1 as newid  from sys_organization  ${ew.customSqlSegment} ")
    String getNewid(@Param(Constants.WRAPPER) Wrapper wrapper);


    /**
     * 查重
     * @param wrapper 条件集
     * @return 重复对象
     */
    @Select("select * from sys_organization  ${ew.customSqlSegment} ")
    SysOrganization check(@Param(Constants.WRAPPER) Wrapper wrapper);
}
